import 'package:get/get.dart';
import 'package:honeypotflutter/modules/autonym/pag/autonym_express/view.dart';
import 'package:honeypotflutter/public/public_url_launcher.dart';
import 'package:honeypotflutter/publicBussine/bussine_image.dart';
import 'package:honeypotflutter/publicBussine/loginInfo/bussine_userInfo.dart';
import '../autonym_text/view.dart';

class AutonymStatusLogic extends GetxController {
  UserInfoLogic _logic = Get.find<UserInfoLogic>();

  RxString icons = RxString(MGImage.image("public_success"));
  RxString status = RxString("已认证");
  RxString remind = RxString("您的实名身份认证审核已通过");
  RxString buttonTitle = RxString("去认证");
  RxBool showButton = RxBool(false);

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    _setUserInfo();
  }

  /*
  * 个人信息判断
  * */
  _setUserInfo() {
    if (_logic.userInfo.realNameStatus == 1 && _logic.userInfo.courierState == 11) {
      return;
    }
    if (_logic.userInfo.realNameStatus == 4) {
      icons.value = MGImage.image("autonym_no_autonym.png", type: ImagePathType.autonym);
      status.value = _logic.userInfo.realNameStatusStr ?? "未认证";
      remind.value = "您还未进行实名身份认证，请立即认证!";
      buttonTitle.value = "去认证";
      showButton.value = true;
      return;
    }

    if (_logic.userInfo.realNameStatus == 2) {
      icons.value = MGImage.image("autonym_jujue.png", type: ImagePathType.autonym);
      status.value = _logic.userInfo.realNameStatusStr ?? "";
      remind.value = _logic.userInfo.remarks ?? "您的实名身份提交被拒绝，请再次认证!";
      buttonTitle.value = "再次认证";
      showButton.value = true;
      return;
    }

    if (_logic.userInfo.realNameStatus == 3) {
      icons.value = MGImage.image("autonym_shenhezhong.png", type: ImagePathType.autonym);
      status.value = _logic.userInfo.realNameStatusStr ?? "";
      remind.value = "认证资料上传成功，请耐心等待审核通过~";
      return;
    }

    if (_logic.userInfo.realNameStatus == 1) {
      if (_logic.userInfo.courierState == 6) {
        icons.value = MGImage.image("autonym_shenhezhong.png", type: ImagePathType.autonym);
        status.value = _logic.userInfo.courierStateStr ?? "";
        remind.value = "认证资料上传成功，请耐心等待审核通过~";
        return;
      }

      if (_logic.userInfo.courierState == 10) {
        icons.value = MGImage.image("autonym_heimingdan.png", type: ImagePathType.autonym);
        status.value = _logic.userInfo.courierStateStr ?? "";
        remind.value = "您已被加入黑名单，请电话联系客户服务人员！";
        buttonTitle.value = "联系客服";
        showButton.value = true;
        return;
      }

      if (_logic.userInfo.courierState == 7) {
        icons.value = MGImage.image("autonym_jujue.png", type: ImagePathType.autonym);
        status.value = _logic.userInfo.courierStateStr ?? "";
        remind.value = "您的快递员身份提交审核被拒绝";
        buttonTitle.value = "再次认证";
        showButton.value = true;
        return;
      }

      icons.value = MGImage.image("autonym_no_autonym.png", type: ImagePathType.autonym);
      status.value = _logic.userInfo.courierStateStr ?? "未认证";
      remind.value = "您还没有进行快递员身份认证,请进行快递员身份认证";
      buttonTitle.value = "去认证";
      showButton.value = true;
      return;
    }

    icons.value = MGImage.image("autonym_no_autonym.png", type: ImagePathType.autonym);
    status.value = _logic.userInfo.realNameStatusStr ?? "未认证";
    remind.value = "您还未进行实名身份认证，请立即认证!";
    buttonTitle.value = "去认证";
    showButton.value = true;
  }

  /*
  * 按钮事件
  * */
  clickAction() async {
    if (_logic.userInfo.realNameStatus == 4 || _logic.userInfo.realNameStatus == 2) {
      Get.to(AutonymTextPage());
      return;
    }

    if (_logic.userInfo.realNameStatus == 1) {
      if (_logic.userInfo.courierState == 10) {
        await HLUrlLauncher.call("4008229599");
        return;
      }
      Get.to(AutonymExpressPage());
      return;
    }
    Get.to(AutonymTextPage());
  }
}
